<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .outer {
        width: 300px;
        height: 300px;
        background-color: green;
        overflow-y: auto;
      }

      .inter {
        width: 100px;
        height: 100px;
        background-color: aqua;
      }
    </style>
  </head>
  <body>
    <!-- 
      按键修饰符
        keyup
        keydown

      
      按键码
        @keyup.13
        @keyup.46
        @keyup.47
      
      按钮别名
        .enter
        .tab
        .esc
        .up
        .down
        .left
        .right
        .space
        .delete
     -->

    <div id="app">
      <input type="text" placeholder="请输入用户名" @keyup.upup="handleLogin" />
      <hr />
      <input type="text" placeholder="请输入密码" @keyup="handlePwd" />
      <button @click="handleLogin">登录</button>
    </div>

    <script src="../lib/vue.js"></script>
    <script>
      // new Vue 之后，配置一些自定义的按键别名
      Vue.config.keyCodes.upup = 38;

      const vm = new Vue({
        el: "#app",
        // 状态数据、响应式数据
        data: {
          fruits: [
            { id: 1, name: "苹果" },
            { id: 2, name: "香蕉" },
          ],
        },
        methods: {
          handleLogin() {
            console.log("handleLogin");
          },
          handlePwd(event) {
            console.log(event.keyCode);
            // 判断键码
            if (event.keyCode === 13) {
              // 调用 handleLogin
              this.handleLogin();
            }
          },
        },
      });
    </script>
  </body>
</html>
